﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pacol
{
    public class Block
    {
        public int _animCoin = 0;
        public bool _hasCoin = true;
        Color _colorTop, _colorLeft, _colorBottom, _colorRight;
        int _x, _y;

        public Block(Color colorTop, Color colorRight, Color colorBottom, Color colorLeft, int x, int y)
        {
            //Get the colors
            _colorTop = colorTop;
            _colorLeft = colorLeft;
            _colorBottom = colorBottom;
            _colorRight = colorRight;

            //Get the position
            _x = x;
            _y = y;
        }

        public Color colorTop
        {
            get { return _colorTop; }
            set { _colorTop = value;}
        }

        public Color colorLeft
        {
            get { return _colorLeft; }
            set { _colorLeft = value; }
        }

        public Color colorBottom
        {
            get { return _colorBottom; }
            set { _colorBottom = value; }
        }

        public Color colorRight
        {
            get { return _colorRight; }
            set { _colorRight = value; }
        }

        public int x
        {
            get { return _x; }
        }

        public int y
        {
            get { return _y; }
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime)
        {

        }

        public void DrawGround(SpriteBatch spriteBatch, int blockSize, int thicknessBorder, Color playerColor)
        {
            //Create the rectangle corresponding to the block.
            Rectangle titleSafeRectangle = new Rectangle(_x, _y, blockSize, blockSize);

            // draw floor
            spriteBatch.Draw(Game1._floorTex, new Rectangle(_x, _y, titleSafeRectangle.Width, titleSafeRectangle.Height), Color.White);
        }

       /// <summary>
       /// Will draw a border (hollow rectangle) of the given 'thicknessOfBorder' (in pixels)
       /// of the specified color.
       /// </summary>
       /// <param name="spriteBatch"></param>
       /// <param name="rectangleToDraw"></param>
       /// <param name="thicknessBorder"></param>
        public void DrawBorder(SpriteBatch spriteBatch, int blockSize, int thicknessBorder, Color playerColor)
        {
            //Create the rectangle corresponding to the block.
            Rectangle rectangleToDraw = new Rectangle(_x, _y, blockSize, blockSize);

            //dessin coin si existe
            if(_hasCoin)
                spriteBatch.Draw(Game1._coinTex, new Rectangle(_x, _y + rectangleToDraw.Height / 4, rectangleToDraw.Width, rectangleToDraw.Height / 2), new Rectangle(0, 25 * _animCoin, 25, 25), Color.White);

            // Draw top line
            if (!playerColor.Equals(_colorTop))
                spriteBatch.Draw(Game1._wallTex, new Rectangle(_x, _y, rectangleToDraw.Width + thicknessBorder, thicknessBorder), new Rectangle(0, 0, 24, 2), _colorTop);
           
            // Draw left line
            if (!playerColor.Equals(_colorLeft))
                spriteBatch.Draw(Game1._wallTex, new Rectangle(_x, _y, thicknessBorder, rectangleToDraw.Height), new Rectangle(0, 2, 2, 24), _colorLeft);

            // Draw right line
            if (!playerColor.Equals(_colorRight))
                spriteBatch.Draw(Game1._wallTex, new Rectangle(_x + rectangleToDraw.Width, rectangleToDraw.Y, thicknessBorder, rectangleToDraw.Height), new Rectangle(0, 2, 2, 24), _colorRight);
            
            // Draw bottom line
            if (!playerColor.Equals(_colorBottom))
                spriteBatch.Draw(Game1._wallTex, new Rectangle(_x, _y + rectangleToDraw.Height, rectangleToDraw.Width + thicknessBorder, thicknessBorder), new Rectangle(0, 0, 24, 2), _colorBottom);
        }
    }
}
